|
1
|
|
package org.marketchangers.prayer;
|
|
2
|
|
|
|
3
|
|
import java.util.Date;
|
|
4
|
|
import java.util.LinkedHashSet;
|
|
5
|
|
import java.util.Map;
|
|
6
|
|
import java.util.Set;
|
|
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
public class PrayerRequestQuery {
|
|
13
|
|
private String categoryName;
|
|
14
|
|
private Date endDate;
|
|
15
|
|
private String organizationName;
|
|
16
|
|
private Set requestorUserIds;
|
|
17
|
|
private String searchTerms;
|
|
18
|
|
private Date startDate;
|
|
19
|
|
private String status;
|
|
20
|
|
private boolean dateValid = true;
|
|
21
|
|
|
|
22
|
52
|
public PrayerRequestQuery(Map map) {
|
|
23
|
52
|
this.categoryName = get(map, "categoryName");
|
|
24
|
52
|
this.endDate = getDate(map, "endDate");
|
|
25
|
52
|
this.organizationName = get(map, "organizationName");
|
|
26
|
52
|
this.searchTerms = get(map, "searchTerms");
|
|
27
|
52
|
this.startDate = getDate(map, "startDate");
|
|
28
|
52
|
this.status = get(map, "status");
|
|
29
|
|
|
|
30
|
52
|
this.requestorUserIds = new LinkedHashSet();
|
|
31
|
|
|
|
32
|
52
|
String value = get(map, "requestorUserId");
|
|
33
|
52
|
if (value != null) {
|
|
34
|
20
|
requestorUserIds.add(value);
|
|
35
|
|
}
|
|
36
|
|
|
|
37
|
|
}
|
|
38
|
|
|
|
39
|
|
|
|
40
|
12
|
public String getCategoryName() {
|
|
41
|
12
|
return categoryName;
|
|
42
|
|
}
|
|
43
|
|
|
|
44
|
24
|
public Date getEndDate() {
|
|
45
|
24
|
return endDate;
|
|
46
|
|
}
|
|
47
|
|
|
|
48
|
84
|
public Set getRequestorUserIds() {
|
|
49
|
84
|
return requestorUserIds;
|
|
50
|
|
}
|
|
51
|
|
|
|
52
|
6
|
public String getOrganizationName() {
|
|
53
|
6
|
return organizationName;
|
|
54
|
|
}
|
|
55
|
|
|
|
56
|
12
|
public String getSearchTerms() {
|
|
57
|
12
|
return searchTerms;
|
|
58
|
|
}
|
|
59
|
|
|
|
60
|
24
|
public Date getStartDate() {
|
|
61
|
24
|
return startDate;
|
|
62
|
|
}
|
|
63
|
|
|
|
64
|
12
|
public String getStatus() {
|
|
65
|
12
|
return status;
|
|
66
|
|
}
|
|
67
|
|
|
|
68
|
8
|
public boolean equals(Object o) {
|
|
69
|
8
|
if (o == null) {
|
|
70
|
0
|
return false;
|
|
71
|
|
}
|
|
72
|
|
|
|
73
|
8
|
if (!(o instanceof PrayerRequestQuery)) {
|
|
74
|
0
|
return false;
|
|
75
|
|
}
|
|
76
|
|
|
|
77
|
8
|
PrayerRequestQuery other = (PrayerRequestQuery) o;
|
|
78
|
|
|
|
79
|
8
|
return equals(this.categoryName, other.categoryName)
|
|
80
|
|
&& equals(this.endDate, other.endDate)
|
|
81
|
|
&& equals(this.organizationName, other.organizationName)
|
|
82
|
|
&& equals(this.requestorUserIds, other.requestorUserIds)
|
|
83
|
|
&& equals(this.searchTerms, other.searchTerms)
|
|
84
|
|
&& equals(this.startDate, other.startDate)
|
|
85
|
|
&& equals(this.status, other.status);
|
|
86
|
|
}
|
|
87
|
|
|
|
88
|
28
|
public boolean hasCategoryName() {
|
|
89
|
28
|
return categoryName != null;
|
|
90
|
|
}
|
|
91
|
|
|
|
92
|
30
|
public boolean hasEndDate() {
|
|
93
|
30
|
return endDate != null;
|
|
94
|
|
}
|
|
95
|
|
|
|
96
|
6
|
public boolean hasOrganizationName() {
|
|
97
|
6
|
return organizationName != null;
|
|
98
|
|
}
|
|
99
|
|
|
|
100
|
32
|
public boolean hasRequestorUserIds() {
|
|
101
|
32
|
return !requestorUserIds.isEmpty();
|
|
102
|
|
}
|
|
103
|
|
|
|
104
|
28
|
public boolean hasSearchTerms() {
|
|
105
|
28
|
return searchTerms != null;
|
|
106
|
|
}
|
|
107
|
|
|
|
108
|
30
|
public boolean hasStartDate() {
|
|
109
|
30
|
return startDate != null;
|
|
110
|
|
}
|
|
111
|
|
|
|
112
|
28
|
public boolean hasStatus() {
|
|
113
|
28
|
return status != null;
|
|
114
|
|
}
|
|
115
|
|
|
|
116
|
4
|
public int hashCode() {
|
|
117
|
4
|
int result = 11;
|
|
118
|
|
|
|
119
|
4
|
result = result * 37 + hashCode(categoryName);
|
|
120
|
4
|
result = result * 37 + hashCode(endDate);
|
|
121
|
4
|
result = result * 37 + hashCode(organizationName);
|
|
122
|
4
|
result = result * 37 + hashCode(requestorUserIds);
|
|
123
|
4
|
result = result * 37 + hashCode(searchTerms);
|
|
124
|
4
|
result = result * 37 + hashCode(startDate);
|
|
125
|
4
|
result = result * 37 + hashCode(status);
|
|
126
|
|
|
|
127
|
4
|
return result;
|
|
128
|
|
}
|
|
129
|
|
|
|
130
|
|
|
|
131
|
|
|
|
132
|
6
|
public boolean hasValidDate() {
|
|
133
|
6
|
if ((startDate != null)
|
|
134
|
|
&& (endDate != null)
|
|
135
|
|
&& (startDate.after(endDate))) {
|
|
136
|
0
|
return false;
|
|
137
|
|
}
|
|
138
|
6
|
return dateValid;
|
|
139
|
|
}
|
|
140
|
|
|
|
141
|
|
|
|
142
|
364
|
private String get(Map query, String key) {
|
|
143
|
364
|
if (query.containsKey(key)) {
|
|
144
|
112
|
String value = ((String[]) query.get(key))[0];
|
|
145
|
112
|
return value.equals("") ? null : value;
|
|
146
|
|
} else {
|
|
147
|
252
|
return null;
|
|
148
|
|
}
|
|
149
|
|
}
|
|
150
|
|
|
|
151
|
104
|
private Date getDate(Map query, String key) {
|
|
152
|
104
|
String value = get(query, key);
|
|
153
|
|
|
|
154
|
104
|
if (value == null) {
|
|
155
|
60
|
return null;
|
|
156
|
|
}
|
|
157
|
|
|
|
158
|
44
|
Date date = DateUtil.validateDateField(value);
|
|
159
|
44
|
if(date==null){
|
|
160
|
8
|
dateValid=false;
|
|
161
|
|
}
|
|
162
|
44
|
return date;
|
|
163
|
|
}
|
|
164
|
|
|
|
165
|
56
|
private boolean equals(Object lhs, Object rhs) {
|
|
166
|
56
|
return lhs == null ? rhs == null : lhs.equals(rhs);
|
|
167
|
|
}
|
|
168
|
|
|
|
169
|
28
|
private int hashCode(Object o) {
|
|
170
|
28
|
return o == null ? 0 : o.hashCode();
|
|
171
|
|
}
|
|
172
|
|
}
|
|
173
|
|
|